package com.ray.controller;

import com.ray.enums.FlagEnum;
import com.ray.exception.ServiceException;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ExceptionTestController {

    @RequestMapping("/index")
    public String index(){
        int i = 1/0;
        return "index";
    }

    @RequestMapping("/index2/{id}")
    public String index2(@PathVariable Integer id){
        if(id==1){
            throw new ServiceException("数据异常");
        }
        return "index";
    }

    @RequestMapping("/index3/{id}")
    public String index3(@PathVariable Integer id){
        try {
            if(id==3){
                throw new ServiceException("数据异常");
            }
        }catch (Exception e){
            System.out.println(e+"---");
            return e.getMessage();
        }

        return "index";
    }

    @RequestMapping("/index4/{id}")
    public String index4(@PathVariable Integer id){
        return FlagEnum.PAY_ERROR.getMsg();
    }
}
